package com.example.android_entrainement;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by jim on 20/07/13.
 */
public class HearthstoneSQLiteDB extends SQLiteOpenHelper {

    private static final String CARDS_TABLE = "CardsTable";
    private static final String COL_ID = "ID";
    private static final String COL_CARD_NAME = "Name";
    private static final String COL_CARD_RARITY = "Rarity";
    private static final String COL_CARD_CAPA = "Capacity";
    private static final String COL_IMG_PATH = "ImageResPath";


    private static final String CREATE_BDD = "CREATE TABLE " + CARDS_TABLE + " ("
            + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            COL_CARD_NAME + " TEXT NOT NULL, "+
            COL_CARD_RARITY + " TEXT NOT NULL, " +
            COL_CARD_CAPA + " TEXT NOT NULL, " +
            COL_IMG_PATH + " TEXT);";

    public HearthstoneSQLiteDB(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //on créé la table à partir de la requête écrite dans la variable CREATE_BDD
        db.execSQL(CREATE_BDD);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //On peut fait ce qu'on veut ici moi j'ai décidé de supprimer la table et de la recréer
        //comme ça lorsque je change la version les id repartent de 0
        db.execSQL("DROP TABLE " + CARDS_TABLE + ";");
        onCreate(db);
    }
}

